home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Scene Storm
/
Scene Storm - Volume 1.iso
/
coding
/
asm
/
games
/
texturemapping
/
makeltable.c
< prev
next >
Wrap
C/C++ Source or Header
|
1980-01-03
|
2KB
|
113 lines
#include <exec/types.h>
#include <clib/exec_protos.h>
#include <graphics/view.h>
#include <stdio.h>
#include <dos/dos.h>
#include <math.h>
#define NO_PRAGMAS 1
#include "pd:ifflib/iff.h"
#pragma libcall IFFBase OpenIFF 1e 801
#pragma libcall IFFBase CloseIFF 24 901
#pragma libcall IFFBase FindChunk 2a 902
#pragma libcall IFFBase GetBMHD 30 901
#pragma libcall IFFBase GetColorTab 36 8902
#pragma libcall IFFBase DecodePic 3c 8902
#pragma libcall IFFBase SaveBitMap 42 a9804
/*#pragma libcall IFFBase SaveClip 48 210a9808*/
#pragma libcall IFFBase IFFError 4e 0
#pragma libcall IFFBase GetViewModes 54 901
#pragma libcall IFFBase NewOpenIFF 5a 802
#pragma libcall IFFBase ModifyFrame 60 8902
struct Library *IFFBase,*GfxBase;
ULONG *infile;
void Fail(char *msg)
{
if (msg) printf("%s\n",msg);
if (infile) CloseIFF(infile);
if (IFFBase) CloseLibrary(IFFBase);
exit(0);
}
struct Library *openlib(char *name,ULONG version)
{
struct Library *t1;
t1=OpenLibrary(name,version);
if (! t1)
{
printf("error- needs %s version %d\n",name,version);
Fail(0l);
}
else return(t1);
}
int curout=0;
outb(c)
{
if (! curout) printf("\n\tdc.b\t"); else printf(",");
printf("$%02x",c);
curout++;
if (curout==15) curout=0;
}
struct Colormap *mycm;
ULONG r[256],g[256],b[256];
main(argc,argv)
int argc;
char **argv;
{
IFFBase=openlib("iff.library",0);
GfxBase=openlib("graphics.library",39);
if (argc==3)
{
if (infile=OpenIFF(argv[1]))
{
ULONG *form,*chunk;
ULONG count;
UBYTE *ptr;
ULONG i;
double lightvalue;
lightvalue=atof(argv[2]);
mycm=GetColorMap(256l);
chunk=FindChunk(infile,ID_CMAP);
if (! chunk) Fail("no color table");
chunk++;
count=(*(chunk++))/3;
ptr=chunk;
if (count>256) count=256;
for(i=0;i<count;i++)
{
r[i]=*(ptr++)<<24;
g[i]=*(ptr++)<<24;
b[i]=*(ptr++)<<24;
SetRGB32CM(mycm,i,r[i],g[i],b[i]);
}
printf("; light table for radiance=%1.2f\n",lightvalue);
for(i=0;i<256;i++)
{
int found;
double r1,g1,b1;
r1=r[i]*lightvalue;
g1=g[i]*lightvalue;
b1=b[i]*lightvalue;
found=FindColor(mycm,(ULONG) r1,(ULONG) g1, (ULONG) b1,127);
outb(found);
}
printf("\n");
Fail(0);
}
} else Fail("can't open file");
}